package com.framework.boc.admin.security.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

@Service
public class ResponseUtil {

    /**
     * 消息写入response
     * @param response      输出消息体
     * @param map           输出消息
     * @param status        回复状态
     * @throws IOException
     */
    public void WriteInfoToResponse(HttpServletResponse response, Map<String, Object> map, int status) throws IOException {
        response.setContentType("application/json;charset=utf-8");
        response.setStatus(status);
        PrintWriter pw = response.getWriter();
        pw.write(new ObjectMapper().writeValueAsString(map));
        pw.flush();
        pw.close();
    }

}
